package com.TestHeiMa02;

// 1. 定义手机类
class MobilePhone {
    public void call() {
        System.out.println("打电话");
    }

    public void sendMessage() {
        System.out.println("发短信");
    }
}

// 2. 定义接口 IPlay
interface IPlay {
    void playGame();
}

// 3. 定义旧手机类继承手机类
class OldMobilePhone extends MobilePhone {
}

// 4. 定义新手机继承手机类实现 IPlay 接口
class NewMobilePhone extends MobilePhone implements IPlay {
    @Override
    public void playGame() {
        System.out.println("玩游戏");
    }
}

// 5. 定义测试类
class Tester {
    public void usePhone(MobilePhone phone) {
        phone.call();
        phone.sendMessage();
        if (phone instanceof NewMobilePhone) {
            ((NewMobilePhone) phone).playGame();
        }
    }
}

public class Main {
    public static void main(String[] args) {
        Tester tester = new Tester();
        OldMobilePhone oldPhone = new OldMobilePhone();
        tester.usePhone(oldPhone);
        NewMobilePhone newPhone = new NewMobilePhone();
        tester.usePhone(newPhone);
    }
}